//
//  Team9SubjectOtherViewController.m
//  Team9Project
//
//  Created by dllo on 15/10/19.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9SubjectOtherViewController.h"
#import "Team9SubjectOtherTableViewCell.h"
#import "Team9SubjectOtherModel.h"
#import <UIImageView+WebCache.h>
#import "JQAFNetworkTool.h"
#import "Team9DesignVC.h"

#define WID 375.0

@interface Team9SubjectOtherViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *otherTableView;
@property (nonatomic, strong) NSMutableArray *otherArr;

@end

@implementation Team9SubjectOtherViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

#pragma mark 设计师作品push页面
    
    self.view.backgroundColor = [UIColor greenColor];
    self.navigationController.navigationBar.translucent = NO;
    self.title = self.str;
    
    self.otherTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEGHT - 64 - 49) style:UITableViewStylePlain];
    [self.view addSubview:self.otherTableView];
    self.otherTableView.dataSource = self;
    self.otherTableView.delegate = self;
    
    [self createData];
}

#pragma mark 数据解析
- (void)createData{
    NSString *str = [NSString stringWithFormat:@"http://api.meilijia.com/app/featured_subject?subject_id=%ld", self.ID];
    
    [JQAFNetworkTool getUrl:str body:nil result:JQJSON headerFile:nil success:^(id result) {
        
        NSMutableDictionary *dic = result[@"data"][@"featured_subject"][@"info"];
        self.otherArr = [NSMutableArray array];
        self.otherArr = [Team9SubjectOtherModel baseModelByArr:dic[@"collections"]].mutableCopy;
        
        [self.otherTableView reloadData];
    } failure:^(NSError *error) {
        
    }];
 
}

#pragma mark 自适应高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    Team9SubjectOtherModel *model = self.otherArr[indexPath.row];
    return [Team9Tool heightByFloatSize:14 / WID * WIDTH width:305 / WID * WIDTH With:model.title] + [Team9Tool heightByFloatSize:14 / WID * WIDTH width:305 / WID * WIDTH With:model.title_sub] + 245 / WID * WIDTH;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.otherArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse = @"reuse";
    Team9SubjectOtherTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if (!cell) {
        cell = [[Team9SubjectOtherTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
    }
    Team9SubjectOtherModel *model = self.otherArr[indexPath.row];
    [cell.cover_picImageView sd_setImageWithURL:[NSURL URLWithString:model.cover_pic] placeholderImage:[UIImage imageNamed:@"111"]];
    [cell.author_faceImageView sd_setImageWithURL:[NSURL URLWithString:model.author_face] placeholderImage:[UIImage imageNamed:@"333"]];
    cell.titleLabel.text = model.title;
    cell.title_subLabel.text = model.title_sub;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Team9SubjectOtherModel *model = self.otherArr[indexPath.row];
    Team9DesignVC *designVC = [Team9DesignVC new];
    designVC.url = [NSString stringWithFormat:@"http://api.meilijia.com/app/collection_page2?col_id=%ld&tab=photo", model.id];
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:designVC animated:YES];
    self.hidesBottomBarWhenPushed = NO;
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
